package cn.itcast.service.impl;

import cn.itcast.dao.MemberDao;
import cn.itcast.dao.OrderDao;
import cn.itcast.service.MemberService;
import cn.itcast.service.ReportService;
import cn.itcast.utils.DateUtils;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService {
    @Autowired
    private MemberDao memberDao;
    @Autowired
    private OrderDao orderDao;
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        // 会员数据统计
        // 获取今天日期
        String reportDate = DateUtils.parseDate2String(DateUtils.getToday());
        // 获取本周一的日期
        String mondayDay = DateUtils.parseDate2String(DateUtils.getThisWeekMonday(new Date()));
        // 获取本月初日期
        String monthDay = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        // 创建空map集合
        Map<String,Object> map = new HashMap<>();
        // 获取今天新增会员数
        Integer todayNewMember = memberDao.findMemberCountByDate(reportDate);
        // 获取总会员数
        Integer totalMember = memberDao.findMemberTotalCount();
        // 获取本周新增会员数
        Integer thisWeekNewMember = memberDao.findMemberCountAfterDate(mondayDay);
        // 获取本月新增会员数
        Integer thisMonthNewMember = memberDao.findMemberCountAfterDate(monthDay);
        // 添加到map
        map.put("reportDate",reportDate);
        map.put("todayNewMember",todayNewMember);
        map.put("totalMember",totalMember);
        map.put("thisWeekNewMember",thisWeekNewMember);
        map.put("thisMonthNewMember",thisMonthNewMember);

        // 预约到诊数据统计
        // 获取今日预约数
        Integer todayOrderNumber = orderDao.findOrderCountByDate(reportDate);
        // 获取今日到诊数
        Integer todayVisitsNumber = orderDao.findVisitsCountByDate(reportDate);
        // 获取本周预约数
        Integer thisWeekOrderNumber = orderDao.findOrderCountAfterDate(mondayDay);
        // 获取本周到诊数
        Integer thisWeekVisitsNumber = orderDao.findVisitsCountAfterDate(mondayDay);
        // 获取本月预约数
        Integer thisMonthOrderNumber = orderDao.findOrderCountAfterDate(monthDay);
        // 获取本月到诊数
        Integer thisMonthVisitsNumber = orderDao.findVisitsCountAfterDate(monthDay);
        // 添加到map
        map.put("todayOrderNumber",todayOrderNumber);
        map.put("todayVisitsNumber",todayVisitsNumber);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);

        // 热门套餐统计
        List<Map> hotSetmeal = orderDao.findHotSetmeal();
        map.put("hotSetmeal",hotSetmeal);
        return map;
    }
}
